package com.szqhyxj.youxiangju.sys.components.view.popview;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.update.bean.UpdateInfo;

import butterknife.BindView;

/**
 * XiaoPanYu
 * on 2018/10/27
 */
public class UpdatePopView extends BaseDialog{
    @BindView(R.id.version_name)
    TextView versionName;
    @BindView(R.id.content_01)
    TextView content01;
    @BindView(R.id.content_02)
    TextView content02;
    @BindView(R.id.content_03)
    TextView content03;
    @BindView(R.id.nextTime)
    Button nextTime;
    @BindView(R.id.immediatelyGo)
    Button immediatelyGo;
    @BindView(R.id.erect_line)
    View erectLine;

    private onClickImmediatelyGo onClickImmediatelyGo;

    private String title;
    private int imgId;
    private UpdateInfo updateInfo;

    public UpdatePopView(Context context, UpdateInfo updateInfo){
        super(context);
        this.updateInfo = updateInfo;
        versionName.setText(updateInfo.getVersionName());
        TextView[] textViews = new TextView[]{content01,content02,content03};
        if(!TextUtils.isEmpty(updateInfo.getNewContent()));{
            String[] contents = updateInfo.getNewContent().split(";");
            for(int i=0;i<contents.length;i++){
                textViews[i].setText(contents[i]);
            }
        }

        if(updateInfo.getUpdateType().equals("1")){//（0 正常更新 1 强制更新）
            nextTime.setVisibility(View.GONE);
            erectLine.setVisibility(View.GONE);
        }

        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);

        nextTime.setOnClickListener(this);
        immediatelyGo.setOnClickListener(this);
    }

    @Override
    protected View initDialogView(Context context){
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_up, null);

        versionName = view.findViewById(R.id.version_name);
        content01 = view.findViewById(R.id.content_01);
        content02 = view.findViewById(R.id.content_02);
        content03 = view.findViewById(R.id.content_03);
        nextTime = view.findViewById(R.id.nextTime);
        immediatelyGo = view.findViewById( R.id.immediatelyGo);
        erectLine = view.findViewById(R.id.erect_line);

        return view;
    }



    @Override
    public void onClick(View v){
        super.onClick(v);
        switch(v.getId()){
            case R.id.nextTime:
                dismiss();
                break;
            case R.id.immediatelyGo:
                dismiss();
                if(onClickImmediatelyGo!=null)
                    onClickImmediatelyGo.onImmediatelyGo(updateInfo.getDownloadLinks());
                break;
        }
    }


    public interface onClickImmediatelyGo{
        public void onImmediatelyGo(String url);
    }

    public void setOnClickImmediatelyGo(UpdatePopView.onClickImmediatelyGo onClickImmediatelyGo){
        this.onClickImmediatelyGo = onClickImmediatelyGo;
    }
}



